/*
 * 矩阵,向量工具: 向量*矩阵,向量组*矩阵, 矩阵*向量, 矩阵*向量组
 *
 * 历史:
 *	2019-12-16 姚彧 创建
 */

#ifndef _YY_FMATRIX_VECTOR_UTIL_H_
#define _YY_FMATRIX_VECTOR_UTIL_H_

#include "FVector.h"
#include "Matrix.h"
#include <vector>

#define FVECTOR_M FVector<m,Real>

namespace yy
{
	namespace math
	{
		// 向量乘矩阵
		FMATRIX_TEMPLATE
			FVECTOR_M operator*(FVECTOR const& x, FMATRIX_NM const A)
		{
			FVECTOR_M y;
			for (int i = 0; i < m; ++i)
				for (int r = 0; r < n; ++r)
					y[i] += x[i] * A(r, i);
			return y;
		}

		// 向量组乘矩阵
		FMATRIX_TEMPLATE
			std::vector<FVECTOR_M> operator*(std::vector<FVECTOR> const& X, FMATRIX_NM const A)
		{
			std::vector<FVECTOR_M> Y;
			for (auto iter = X.begin(); iter != X.end(); ++iter)
				Y.push_back((*iter) * A);
			return Y;
		}

		// 矩阵乘向量
		FMATRIX_TEMPLATE
			FVECTOR_M operator*(FMATRIX_MN const A, FVECTOR const& x)
		{
			FVECTOR_M y;
			for (int i = 0; i < m; ++i)
				for (int j = 0; j < n; ++j)
					y[i] += A(i, j) * x[j];
			return y;
		}

		// 矩阵乘向量组
		FMATRIX_TEMPLATE
			std::vector<FVECTOR_M> operator*(FMATRIX_MN const A, std::vector<FVECTOR> const& X)
		{
			std::vector<FVECTOR_M> Y;
			for (auto iter = X.begin(); iter != X.end(); ++iter)
				Y.push_back(A * (*iter));
			return Y;
		}
	}
}

#endif	//_YY_FMATRIX_VECTOR_UTIL_H_